<template>
	<view class="classify">
		<view class="search_box">
				<u-search :show-action="false" v-model="params.nickname" placeholder="请输入搜索商家" @search="getList"></u-search>
		</view>
		<view style="height:42px;"></view>
	
		<view class="k_box">
			<view style="position: relative;">
				<view :class="['keyword']" @click="changeFirst(item,index)" v-for="(item,index) in firstCate" :key="index">

					<view>
						<text :class="[kind==index?'name_check':'','fname']">{{item.name}}</text>
					</view>
				</view>
			</view>

		</view>
		<view :style="'height:'+heightCi*45+'px;'"></view>


	<view class="shop_box">

				<view class="shop_info" @click="toUrl(item)" v-for="(item,index) in list" :key="index">

					<view class="shop_head">
						<image :src="item.image" class="shop_img"></image>

						<view>
							<view class="shop_name">{{item.nickname}}</view>
							<view class="label_box">
								<view class="label" v-for="(items,indexs) in item.label" :key="indexs">
									{{items.name}}
								</view>
							</view>
							<view class="time_box">
								<text>营业时间: {{item.start}}-{{item.end}}</text><text style="margin-left:20rpx;" v-if="item.distance">{{item.distance}}</text>
							</view>
						</view>
					</view>

					<scroll-view :show-scrollbar="false" :scroll-x="true" class="scr">
						<view class="scr_box" v-for="(items,indexs) in item.goods" :key="indexs">
							<view class="img_box">
								<image mode="aspectFit" :src="items.main_image"></image>
							</view>
							<view class="src_name">{{items.name}}</view>
							<view class="src_price">¥{{items.price}}</view>
						</view>
					</scroll-view>

				</view>

			</view>
         
		   <view v-if="show" class="bitmap">
		 		<image :src="none" mode="widthFix"></image>
		 		<view>亲！暂无商户信息</view>
		 	</view>



	</view>
</template>

<script>
	const app = getApp().globalData;
	const {
		imgRemote
	} = app;


	export default {
		components: {

		},
		data() {
			return {
				heightNum: 4,
				heightCi: 1,
				kind: 0,
				firstCate: [],
				show: false,
				none: '',
				params: {
					page: 1,
					cate_id:'',
					nickname:'',
					lat:'',
					lng:''
				},
				list: [],
				total: 0
			};
		},
		onShow() {},
		onLoad(e) {
			this.none=this.$imgUrl+'assets/img/none_fw.png';
			if (e.cate_id) {
				this.params.cate_id=e.cate_id;
				this.goodCate(e.cate_id);
			}else{
				this.goodCate();
			}
			this.getJwList();
		},
		methods: {
			toUrl(e){
			   console.log(e);
			  uni.navigateTo({
			  	url:'/pages/zb/info?id='+e.id
			  })	
			},
			changeFirst(e,index){
				this.kind = index;
				this.params.cate_id =  e.id;
				this.getList();
			},
			getJwList() {
				let _ = this;
				uni.getLocation({
					type: 'gcj02',
					success(res) {
						_.params.lat = res.latitude;
						_.params.lng = res.longitude;
						_.getList();
					},
					fail(error) {
						_.getList();
						console.log(error);
					}
				})
			},
			getList() {
				this.params.page = 1;
				this.$get(this.$api.zbShopList, this.params, res => {
					let data = res.data;
			
					if (!data.data.data || data.data.data.length < 1) {
						this.show = true;
					} else {
						this.show = false;
					}
			
					this.list = data.data.data;
					this.total = data.data.total;
				});
			},
			//查找索引
			findIndex(obj, dest) {
				for (let i in obj) {
					if (obj[i].id == dest) {
						return i
					}
				}
			},
			//一级分类
			goodCate(classId='') {
				this.$get(this.$api.zbShopCate, {}, (res) => {
					let {
						data
					} = res;

					if (data.code == 1) {
						//返回索引    
						this.firstCate = data.data;

						if (data.data.length > 0) {
							this.heightCi = Math.ceil(data.data.length / this.heightNum);
						} else {
							this.heightCi = 1;
						}
						let index = this.findIndex(this.firstCate, classId);
						this.kind = index ? index : 0;
						this.params.cate_id = classId ? classId : this.firstCate[0].id;
					}
				})
			},
		},
		onReachBottom() {
           if (this.list.length < this.total) {
           	this.params.page++;
           	this.$get(this.$api.zbShopList, this.params, res => {
           		let data = res.data;
           		data.data.data.forEach(ress => {
           			this.list.push(ress);
           		});
           	});
           }
		}
	};
</script>

<style scoped lang="scss">
	::v-deep .active:before {
		background: #f44b44 !important;
	}

	.k_box {
		position: fixed;
		left: 0;
		top:84rpx;
		width: 100%;
		z-index: 100;
		background-color: white;
		font-size: 26rpx;
		border-bottom: 4rpx solid #F1F1F1;
	}

	.keyword_box {
		box-sizing: border-box;
		padding: 0rpx 0rpx 0 0rpx;
		width: 100%;
		white-space: nowrap;

	}

	.key_img {
		width: 90rpx;
		height: 90rpx;
		border-radius: 50%;
	}

	.keyword {
		width: 25%;
		display: inline-block;
		text-align: center;
		height: 90rpx;
		line-height: 90rpx;
	}

	.keywords {
		width: 20%;
		display: inline-block;
		//margin: 0 20rpx 0 0;
		text-align: center;
		height: 100%;
		box-sizing: border-box;
		padding: 10rpx 0 35rpx 0;
	}

	.key_check {
		background-color: #EEFEF7;
		color: #13AE7E;
	}

	.img_box {
		border: 4rpx solid transparent;
		width: 110rpx;
		height: 110rpx;
		border-radius: 50%;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 10rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.img_check {
		border: 4rpx solid #f44b44;
	}

	.fname {
		background-color: #F1F1F1;
		color: black;
		box-sizing: border-box;
		padding: 12rpx 20rpx;
		border-radius: 25rpx;
		font-size: 26rpx;
	}

	.name_check {
		background-color: #f44b44;
		color: white;


	}

	page {
		background: white;
	}
	

	.zk_box {
		text-align: center;
		position: absolute;
		right: 0;
		top: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: white;
		height: 100%;
		font-weight: bold;
		width: 60rpx;
	}

	.top_box {
		background-color: white;
	}

	.up_box {
		display: flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		padding: 20rpx 0;
		border-top: 1rpx solid #F2F2F2;
		color: #888888;
		font-size: 26rpx;
	}

	.mr {
		margin-right: 60rpx;
	}

	scroll-view ::-webkit-scrollbar {
		display: none !important;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}

	::-webkit-scrollbar {
		display: none;
	}
	
	.shop_box {
			box-sizing: border-box;
			padding:  0 20rpx;
		}
	
		.shop_info {
			background-color: white;
			border-radius: 20rpx;
			box-sizing: border-box;
			padding: 20rpx;
	        margin-top: 20rpx;
		}
	
		.shop_head {
			display: flex;
			margin-bottom: 20rpx;
		}
	
		.shop_img {
			width: 140rpx;
			height: 140rpx;
			border-radius: 15rpx;
			margin-right: 15rpx;
		}
	
		.shop_name {
			font-weight: bold;
			font-size: 32rpx;
		}
	
		.label_box {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			//margin-top: 10rpx;
		}
	
		.label {
			background-color: #EDFDE6;
			box-sizing: border-box;
			padding: 2rpx 5rpx;
			color: #2A7C2F;
			font-size: 22rpx;
			margin-right: 10rpx;
			margin-top: 15rpx;
		}
	
		.time_box {
			font-size: 22rpx;
			color: #666666;
			margin-top: 15rpx;
		}
	
		.scr {
		
			width: 100%;
			white-space: nowrap;
		}
	
		.scr_box {
			width: 180rpx;
			display: inline-block;
			margin-right:20rpx;
		}
	
		.img_box {
			width: 180rpx;
			height: 180rpx;
	        border: 1rpx solid #EBEBEB;
			border-radius: 15rpx;
			image {
				width: 100%;
				height: 100%;
				object-fit: contain;
			}
		}
		.src_name{
			text-overflow: ellipsis;
			white-space: nowrap;
			overflow: hidden;
			font-size: 24rpx;
			margin-top: 10rpx;
		}
		.src_price{
			color:#FF5757;
			font-size: 24rpx;
			font-weight: bold;
			margin-top: 10rpx;
		}
	
	.search_box{
		box-sizing: border-box;
		padding: 20rpx 20rpx 0rpx 20rpx;
		background-color: white;
		position: fixed;
		top:0;
		left:0;
		width: 100%;
	}
	
	.bitmap{
		margin-top: 50rpx;
		text-align: center;
		image{
			width: 60%;
		}
	}
	
</style>